package com.example.yk_lx.addGroup;

import androidx.lifecycle.Observer;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ToastUtils;
import com.example.yk_lx.R;
import com.example.yk_lx.baseMVVM.BaseActivity;
import com.example.yk_lx.databinding.ActivityAddGroupBinding;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMGroupManager;
import com.hyphenate.chat.EMGroupOptions;

@Route(path = "/app/AddGroupActivity")
public class AddGroupActivity extends BaseActivity<ActivityAddGroupBinding,AddFroupViewModel> {

    @Override
    protected int bindLayout() {
        return R.layout.activity_add_group;
    }

    @Override
    protected void initView() {
        dataBinding.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EMGroupOptions option = new EMGroupOptions();
                option.maxUsers = 100;
                option.style = EMGroupManager.EMGroupStyle.EMGroupStylePrivateMemberCanInvite;
                viewModel.addGroup(dataBinding.groupName.getText().toString(),
                        dataBinding.groupDesc.getText().toString(),
                        new String[]{EMClient.getInstance().getCurrentUser()},
                        dataBinding.groupReason.getText().toString(),option);
            }
        });
    }

    @Override
    protected void initData() {
        viewModel.success.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
                finish();//成功结束当前界面
            }
        });
        viewModel.fail.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
            }
        });
    }

    @Override
    protected Class<AddFroupViewModel> getViewModel() {
        return AddFroupViewModel.class;
    }


}